/**
 * Copyright (c) 2011-2020, hubin (jobob@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.agree.util.excel.entity;

import com.agree.util.excel.util.StringUtils;

/**
 * <p>
 * 表字段信息
 * </p>
 *
 * @author YangHu
 * @since 2016-12-03
 */
public class TableField {

    private String name;
    private String type;
    private String comment;
    /**
     * 字段最大整数位长度,用于校验
     */
    private int maxIntegerLength = 0;
    /**
     * 字段最大小数位长度,用于校验
     */
    private int maxFractionLength = 0;
    /**
     * 是否允许为空，用于校验
     */
    private String isMust = "N";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        if(type.contains("(") && type.contains(")")) {
            this.type = type.substring(0,type.indexOf("("));
            String length = type.substring(type.indexOf("(")+1,type.indexOf(")")).trim();
            if(length.contains(",")) {
                String[] split = length.split(",");
                this.maxFractionLength = Integer.parseInt(split[1]);
                this.maxIntegerLength = Integer.parseInt(split[0]);
            } else {
                this.maxIntegerLength = Integer.parseInt(length);
            }
        } else {
            this.type = type;
        }
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public int getMaxIntegerLength() {
        return maxIntegerLength;
    }

    public int getMaxFractionLength() {
        return maxFractionLength;
    }

    public String getMust() {
        return isMust;
    }

    public void setMust(String must) {
        isMust = must;
    }

    public String getHumpName() {
        return StringUtils.underlineToCamel(name);
    }

    @Override
    public String toString() {
        return "TableField{" +
                "name='" + name + '\'' +
                ", type='" + type + '\'' +
                ", comment='" + comment + '\'' +
                ", maxIntegerLength=" + maxIntegerLength +
                ", maxFractionLength=" + maxFractionLength +
                ", isMust='" + isMust + '\'' +
                '}';
    }
}
